package com.ruoyi.jt808.vo;

import java.util.Arrays;

import com.alibaba.fastjson2.annotation.JSONField;
import io.netty.channel.Channel;
import lombok.Data;

@Data
public class PackageData {

	/**
	 * 16byte 消息头
	 */
	protected MsgHeader msgHeader;

	// 消息体字节数组
	@JSONField(serialize=false)
	protected byte[] msgBodyBytes;

	@JSONField(serialize=false)
	protected Channel channel;

	/** 校验码byte[1] **/
	private byte[] checkByte;

	/**
	 * 校验码 1byte
	 */
	protected int checkSum;

	/** 数据包是否验证通过 **/
	private boolean isValid = true;

	/** 消息体byte[] **/
	private byte[] fullMsgBytes;
	/**
	 * 软件协议 2011 or 2013 or 2019
	 */
	private String softVersion;

	private Integer mainSign;

	@Override
	public String toString() {
		return "PackageData [msgHeader=" + msgHeader + ", msgBodyBytes=" + Arrays.toString(msgBodyBytes) + ", checkSum="
				+ checkSum + ", address=" + channel + "]";
	}

	@Data
	public static class MsgHeader {
		// 消息ID
		protected Integer msgId;

		/////// ========消息体属性
		// byte[2-3]
		protected int msgBodyPropsField;
		// 消息体长度
		protected int msgBodyLength;
		// 数据加密方式
		protected int encryptionType;
		// 是否分包,true==>有消息包封装项
		protected boolean hasSubPackage;
		// 保留位[14-15]
		protected String reservedBit;
		/////// ========消息体属性
		/** 消息体属性 **/
		private Integer headerMsgAttribute;
		// 终端手机号
		protected String terminalPhone;
		// 流水号
		protected int flowId;

		//////// =====消息包封装项
		// byte[12-15]
		protected int packageInfoField;
		// 消息包总数(word(16))
		protected long totalSubPackage;
		// 包序号(word(16))这次发送的这个消息包是分包中的第几个消息包, 从 1 开始
		protected long subPackageSeq;
		//////// =====消息包封装项

		@Override
		public String toString() {
			return "MsgHeader [msgId=" + msgId + ", msgBodyPropsField=" + msgBodyPropsField + ", msgBodyLength="
					+ msgBodyLength + ", encryptionType=" + encryptionType + ", hasSubPackage=" + hasSubPackage
					+ ", reservedBit=" + reservedBit + ", terminalPhone=" + terminalPhone + ", flowId=" + flowId
					+ ", packageInfoField=" + packageInfoField + ", totalSubPackage=" + totalSubPackage
					+ ", subPackageSeq=" + subPackageSeq + "]";
		}

	}

}
